tools/ocaml/libs: Allocate the correct amount of memory for Abstract_tag
authorAndrew Cooper <andrew.cooper3@citrix.com>
Tue, 31 Jan 2023 10:59:42 +0000 (10:59 +0000)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Thu, 9 Feb 2023 15:55:25 +0000 (15:55 +0000)
commit5797b798a542a7e5be34698463152cb92f18776f
treec04d2b85ceb46cf7d1880b8dfe56e3f19bd891c4
parent2c21e1bee6d62cbd523069e839086addf35da9f2
tools/ocaml/libs: Allocate the correct amount of memory for Abstract_tag

caml_alloc() takes units of Wsize (word size), not bytes.  As a consequence,
we're allocating 4 or 8 times too much memory.

Ocaml has a helper, Wsize_bsize(), but it truncates cases which aren't an
exact multiple.  Use a BUILD_BUG_ON() to cover the potential for truncation,
as there's no rounding-up form of the helper.

Fixes: 8b7ce06a2d34 ("ocaml: Add XC bindings.")
Fixes: d3e649277a13 ("ocaml: add mmap bindings implementation.")
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Acked-by: Christian Lindig <christian.lindig@citrix.com>
(cherry picked from commit 36eb2de31b6ecb8787698fb1a701bd708c8971b2)
tools/ocaml/libs/mmap/Makefile
tools/ocaml/libs/mmap/xenmmap_stubs.c
tools/ocaml/libs/xc/xenctrl_stubs.c